<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<style type="text/css">
	*{
		padding: 0;
		margin: 0;
	}
	img{
		width: 190px;
		height: 150px;
		margin: 4px;
		float: left;
	}
</style>
<script type="text/javascript">
	window.onload = function(){
		var imgs = document.getElementsByTagName('img');
		// 循环图片，
		for(var i=0;i<imgs.length;i++){
			// 给当前循环到的图片对象加一个xuhao属性，属性里面存当前i的值
			imgs[i].xuhao = i;	
			imgs[i].onclick = function(){
				alert(this.xuhao);
			}
		}
	}
</script>
</head>

<body>
<!-- img[src=images/$.jpg]*3 -->
<img src="images/1.jpg" alt="" />
<img src="images/2.jpg" alt="" />
<img src="images/3.jpg" alt="" />
</body>
</html>
